<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<script>	

		// 合并
		function merge (left, right) {
			var result = [];		// 存放数组
			while (left.length > 0 && right.length > 0) {
				if (left[0] < right[0]) {
					result.push(left.shift())
				} else {
					result.push(right.shift())
				}
			}					

			return result.concat(left).concat(right)
		}

		// 拆分
		function splitArr(arr) {
			if (arr.length == 1) {
				return arr
			}
			var mid = Math.floor(arr.length / 2)
			
			var left_arr = arr.slice(0, mid)
			var right_arr = arr.slice(mid)

			return merge(splitArr(left_arr), splitArr(right_arr))
		}

		var arr = [6,8,4,5,3,2];
		console.log(splitArr(arr))
	</script>
</body>
</html>